<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"/>
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no"/>
    <meta name="format-detection" content="telephone=no, email=no"/>
    <meta name="apple-mobile-web-app-capable" content="yes"/>
    <meta name="apple-mobile-web-app-status-bar-style" content="black"/>
    <title>Title</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }

        div {
            width: 310px;
            height: 310px;
            border: 1px solid red;
            float: left;
            position: relative;
        }

        #div1 {
            border: 0px;
        }

        #div1 img {
            width: 310px;
            height: 310px;
        }

        #span {
            display: none;
            width: 100px;
            height: 100px;
            background: yellow;
            opacity: .5;
            filter: alpha(opacity:50);
            position: absolute;
            left: 0;
            top: 0;
            z-index: 30;
            cursor: move;
        }

        #div2 {
            overflow: hidden;
            display: none;
        }

        #div2 img {
            width: 930px;
            height: 930px;
            position: absolute;
            left: 0;
            top: 0;
        }
    </style>
</head>

<script>
    window.onload = function () {
        var oSpan = document.getElementById("span");
        var oDiv2 = document.getElementById("div2");
        var oDiv1 = document.getElementById("div1");
        var oBigPic = document.getElementById("bigPic");
        oDiv1.onmouseover = function (ev) {
            var ev = ev || event;
            oSpan.style.display = "block"
            oDiv2.style.display = "block";

        }

        oDiv1.onmousemove = function (ev) {
            var ev = ev || event;
            var l = ev.clientX - oSpan.offsetWidth / 2;
            var t = ev.clientY - oSpan.offsetHeight / 2;
            if (l < 0) {
                l = 0;
            } else if (l > oDiv1.offsetWidth - oSpan.offsetWidth) {
                l = oDiv1.offsetWidth - oSpan.offsetWidth;
            }

            if (t < 0) {
                t = 0
            } else if (t > oDiv1.offsetHeight - oSpan.offsetHeight) {
                t = oDiv1.offsetHeight - oSpan.offsetHeight
            }

            oSpan.style.left = l + "px";
            oSpan.style.top = t + "px";

            var lf = l / (oDiv1.offsetWidth - oSpan.offsetWidth) * (oBigPic.offsetWidth - oDiv2.offsetWidth);
            var tp = t / (oDiv1.offsetHeight - oSpan.offsetHeight) * (oBigPic.offsetHeight - oDiv2.offsetHeight)


            oBigPic.style.left = -lf + "px";
            oBigPic.style.top = -t + "px";


        }

        oDiv1.onmouseout = function (ev) {
            var ev = ev || event;
            oSpan.style.display = "none";
            oDiv2.style.display = "none";
        }


    }
</script>
<body>

<div id="div1">
    <img src="banner.png" alt="">
    <span id="span"></span>
</div>

<div id="div2">
    <img src="banner.png" alt="" id="bigPic">
</div>

</body>
</html>